package random;

import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        Random r = new Random();
        int num = r.nextInt(100) + 1;
        int k = 0;
        for (int i = 0; i < 100; ) {
            k++;
            System.out.println("请输入你猜的数字：(提示：在1～20之间)");
            Scanner sc = new Scanner(System.in);
            int guessnum = sc.nextInt();
            if (guessnum > num) {
                System.out.println("你猜的大了");
            } else if (guessnum < num) {
                System.out.println("你猜的小了");
            } else if (guessnum == num) {
                System.out.println("恭喜你，你猜对了，数字是：" + num + "。你用了" + k + "次猜中！");
                break;//return也可以
            }

        }
    }
}
